﻿Imports QLTHUVIEN.BUS
Imports QLTHUVIEN.DAO
Imports QLTHUVIEN.DTO

Public Class frmBangCap

    Private Sub layDanhSach()
        Dim bangCapBus As BangCapBUS = New BangCapBUS()
        Dim data As DataTable = bangCapBus.LayDanhSach()
        dtgDanhSachBangCap.DataSource = data
    End Sub

    Private Sub frmBangCap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenBangCap.Text = "" Then
            Return
        End If

        Dim bangCapDto As New BangCapDTO()
        bangCapDto.TenBangCap = txtTenBangCap.Text

        Dim bcBus As New BangCapBUS()
        bcBus.ThemBangCap(bangCapDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenBangCap.Text = "" Or txtMaBangCap.Text = "" Then
            Return
        End If

        Dim bangCapDto As New BangCapDTO()
        bangCapDto.MaBangCap = txtMaBangCap.Text
        bangCapDto.TenBangCap = txtTenBangCap.Text

        Dim bcBus As New BangCapBUS()
        bcBus.SuaBangCap(bangCapDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachBangCap_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachBangCap.CellClick
        txtMaBangCap.Text = dtgDanhSachBangCap.CurrentRow.Cells(0).Value.ToString()
        txtTenBangCap.Text = dtgDanhSachBangCap.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim bangCapDto As New BangCapDTO()
        bangCapDto.MaBangCap = txtMaBangCap.Text
        bangCapDto.TenBangCap = txtTenBangCap.Text
        bangCapDto.IsDelete = True

        Dim bcBus As New BangCapBUS()
        bcBus.XoaBangCap(bangCapDto)

        layDanhSach()
    End Sub
End Class